package pe.com.hermes.hermetic.beans;

import java.io.Serializable;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import java.util.SortedSet;
import java.util.TreeSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.Assert;

public class User implements Serializable,UserDetails{
    
    private Collection<GrantedAuthority> authorities;
    private String username;
    private String password;
    private String perfil;
    //private GrantedAuthority authorities[];
    private String company;
    private String nombre;
    private boolean enabled;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;
    
    /*REQ1888- Nuevos atributos para Usuarios por Corp y Razon Social*/
    private int tipClie;
    private String listCodUsu;
    private int codCorp;
    private String desCorp;
    private int boveProp;
    private int boveBanc;
    private String diaHab;
    private int susAnom;
    private int difFecContAt;
    private int difFecContPed;
    private String alertPen;
    private String horAlertPen;
    private int aprAutPed;
    private int    faseAbono;
    private int valiParm;
    
    private String desRazoSoci;
    private int codRazoSoci;
    private String usuWeb;
    private String pasWeb;
    private String ciaWeb;
    private String nomUsuaWeb;
    private int indActi;
    private String fecCaduPass;
    private int numInteConx;
    private boolean indCambPass;
    private boolean indOel;
    private String carEmp;
    private String codAgen;
    private String fecVencUsua;
    private String codSucuHtb;
    private boolean indUsuAdmi;
    private String fecCone;
    private String fecCambPass;
    private String codDpto;
    private String codPrvn;
    private boolean indBloq;
    private String codClie;
    private String nomClie;
    private String desSucuHtb;
    private String desDpto;
    private String desPrvn;
    private String desPerfil;
    private String desIndActi;
    private String desAgen;
    private String fecCrea;
    private String horCrea;
    private String priNomb;
    private String segNomb;
    private String priApel;
    private String segApel;
    private String nombres;
    private String apellidos;
    private String codModu;
    private String desModu;
    private String codPerf;
    private String desPerf;
    private List listClie;    
    private String codPerfOld;
    private String pasWebNew;
    private String pasWebConfirm;
    
    private boolean indProxCambPass;
    private int diaExpiPass;
    private String usuModi;
    private String nomCompModi;
    private int sErro;
    private String sMens;
    private String eMail;
    /**datos usados para registro de Emails*/
    private String codAlert;
    private String desAlert;
    private String cargo;

    private static SortedSet<GrantedAuthority> sortAuthorities(Collection<? extends GrantedAuthority> authorities) {
        Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection");
        // Ensure array iteration order is predictable (as per UserDetails.getAuthorities() contract and SEC-717)
        SortedSet<GrantedAuthority> sortedAuthorities =
            new TreeSet<GrantedAuthority>(new AuthorityComparator());

        for (GrantedAuthority grantedAuthority : authorities) {
            Assert.notNull(grantedAuthority, "GrantedAuthority list cannot contain any null elements");
            sortedAuthorities.add(grantedAuthority);
        }

        return sortedAuthorities;
    }

    public void setPerfil(String perfil) {
        this.perfil = perfil;
    }

    public String getPerfil() {
        return perfil;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getCompany() {
        return company;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getNombre() {
        return nombre;
    }

    public void setCodRazoSoci(int codRazoSoci) {
        this.codRazoSoci = codRazoSoci;
    }

    public int getCodRazoSoci() {
        return codRazoSoci;
    }

    public void setFecCaduPass(String fecCaduPass) {
        this.fecCaduPass = fecCaduPass;
    }

    public String getFecCaduPass() {
        return fecCaduPass;
    }

    public void setNumInteConx(int numInteConx) {
        this.numInteConx = numInteConx;
    }

    public int getNumInteConx() {
        return numInteConx;
    }

    public void setIndCambPass(boolean indCambPass) {
        this.indCambPass = indCambPass;
    }

    public boolean isIndCambPass() {
        return indCambPass;
    }

    public void setIndOel(boolean indOel) {
        this.indOel = indOel;
    }

    public boolean isIndOel() {
        return indOel;
    }

    public void setCarEmp(String carEmp) {
        this.carEmp = carEmp;
    }

    public String getCarEmp() {
        return carEmp;
    }

    public void setCodAgen(String codAgen) {
        this.codAgen = codAgen;
    }

    public String getCodAgen() {
        return codAgen;
    }

    public void setFecVencUsua(String fecVencUsua) {
        this.fecVencUsua = fecVencUsua;
    }

    public String getFecVencUsua() {
        return fecVencUsua;
    }

    public void setIndUsuAdmi(boolean indUsuAdmi) {
        this.indUsuAdmi = indUsuAdmi;
    }

    public boolean isIndUsuAdmi() {
        return indUsuAdmi;
    }

    public void setFecCone(String fecCone) {
        this.fecCone = fecCone;
    }

    public String getFecCone() {
        return fecCone;
    }

    public void setFecCambPass(String fecCambPass) {
        this.fecCambPass = fecCambPass;
    }

    public String getFecCambPass() {
        return fecCambPass;
    }

    public void setCodDpto(String codDpto) {
        this.codDpto = codDpto;
    }

    public String getCodDpto() {
        return codDpto;
    }

    public void setCodPrvn(String codPrvn) {
        this.codPrvn = codPrvn;
    }

    public String getCodPrvn() {
        return codPrvn;
    }

    public void setIndBloq(boolean indBloq) {
        this.indBloq = indBloq;
    }

    public boolean isIndBloq() {
        return indBloq;
    }

    public void setDesDpto(String desDpto) {
        this.desDpto = desDpto;
    }

    public String getDesDpto() {
        return desDpto;
    }

    public void setDesPrvn(String desPrvn) {
        this.desPrvn = desPrvn;
    }

    public String getDesPrvn() {
        return desPrvn;
    }

    public void setDesIndActi(String desIndActi) {
        this.desIndActi = desIndActi;
    }

    public String getDesIndActi() {
        return desIndActi;
    }

    public void setDesAgen(String desAgen) {
        this.desAgen = desAgen;
    }

    public String getDesAgen() {
        return desAgen;
    }

    public void setFecCrea(String fecCrea) {
        this.fecCrea = fecCrea;
    }

    public String getFecCrea() {
        return fecCrea;
    }

    public void setHorCrea(String horCrea) {
        this.horCrea = horCrea;
    }

    public String getHorCrea() {
        return horCrea;
    }

    public void setPriNomb(String priNomb) {
        this.priNomb = priNomb;
    }

    public String getPriNomb() {
        return priNomb;
    }

    public void setSegNomb(String segNomb) {
        this.segNomb = segNomb;
    }

    public String getSegNomb() {
        return segNomb;
    }

    public void setPriApel(String priApel) {
        this.priApel = priApel;
    }

    public String getPriApel() {
        return priApel;
    }

    public void setSegApel(String segApel) {
        this.segApel = segApel;
    }

    public String getSegApel() {
        return segApel;
    }

    public void setNombres(String nombres) {
        this.nombres = nombres;
    }

    public String getNombres() {
        return nombres;
    }

    public void setApellidos(String apellidos) {
        this.apellidos = apellidos;
    }

    public String getApellidos() {
        return apellidos;
    }

    public void setCodModu(String codModu) {
        this.codModu = codModu;
    }

    public String getCodModu() {
        return codModu;
    }

    public void setDesModu(String desModu) {
        this.desModu = desModu;
    }

    public String getDesModu() {
        return desModu;
    }

    public void setCodPerf(String codPerf) {
        this.codPerf = codPerf;
    }

    public String getCodPerf() {
        return codPerf;
    }

    public void setDesPerf(String desPerf) {
        this.desPerf = desPerf;
    }

    public String getDesPerf() {
        return desPerf;
    }

    public void setListClie(List listClie) {
        this.listClie = listClie;
    }

    public List getListClie() {
        return listClie;
    }

    public void setCodPerfOld(String codPerfOld) {
        this.codPerfOld = codPerfOld;
    }

    public String getCodPerfOld() {
        return codPerfOld;
    }

    public void setPasWebNew(String pasWebNew) {
        this.pasWebNew = pasWebNew;
    }

    public String getPasWebNew() {
        return pasWebNew;
    }

    public void setPasWebConfirm(String pasWebConfirm) {
        this.pasWebConfirm = pasWebConfirm;
    }

    public String getPasWebConfirm() {
        return pasWebConfirm;
    }

    public void setIndProxCambPass(boolean indProxCambPass) {
        this.indProxCambPass = indProxCambPass;
    }

    public boolean isIndProxCambPass() {
        return indProxCambPass;
    }

    public void setDiaExpiPass(int diaExpiPass) {
        this.diaExpiPass = diaExpiPass;
    }

    public int getDiaExpiPass() {
        return diaExpiPass;
    }

    public void setUsuModi(String usuModi) {
        this.usuModi = usuModi;
    }

    public String getUsuModi() {
        return usuModi;
    }

    public void setNomCompModi(String nomCompModi) {
        this.nomCompModi = nomCompModi;
    }

    public String getNomCompModi() {
        return nomCompModi;
    }

    public void setSErro(int sErro) {
        this.sErro = sErro;
    }

    public int getSErro() {
        return sErro;
    }

    public void setSMens(String sMens) {
        this.sMens = sMens;
    }

    public String getSMens() {
        return sMens;
    }
       
    public void setEMail(String eMail) {
        this.eMail = eMail;
    }

    public String getEMail() {
        return eMail;
    }

    public void setCodAlert(String codAlert) {
        this.codAlert = codAlert;
    }

    public String getCodAlert() {
        return codAlert;
    }

    public void setDesAlert(String desAlert) {
        this.desAlert = desAlert;
    }

    public String getDesAlert() {
        return desAlert;
    }

    public void setCargo(String cargo) {
        this.cargo = cargo;
    }

    public String getCargo() {
        return cargo;
    }

    public String getDesRazoSoci() {
        return desRazoSoci;
    }

    public void setDesRazoSoci(String desRazoSoci) {
        this.desRazoSoci = desRazoSoci;
    }

    public int getCodCorp() {
        return codCorp;
    }

    public void setCodCorp(int codCorp) {
        this.codCorp = codCorp;
    }

    public String getDesCorp() {
        return desCorp;
    }

    public void setDesCorp(String desCorp) {
        this.desCorp = desCorp;
    }

    public int getBoveProp() {
        return boveProp;
    }

    public void setBoveProp(int boveProp) {
        this.boveProp = boveProp;
    }

    public int getBoveBanc() {
        return boveBanc;
    }

    public void setBoveBanc(int boveBanc) {
        this.boveBanc = boveBanc;
    }

    public String getListCodUsu() {
        return listCodUsu;
    }

    public void setListCodUsu(String listCodUsu) {
        this.listCodUsu = listCodUsu;
    }

    public int getTipClie() {
        return tipClie;
    }

    public void setTipClie(int tipClie) {
        this.tipClie = tipClie;
    }

    public void setDiaHab(String diaHab) {
        this.diaHab = diaHab;
    }

    public String getDiaHab() {
        return diaHab;
    }

    public void setSusAnom(int susAnom) {
        this.susAnom = susAnom;
    }

    public int getSusAnom() {
        return susAnom;
    }

    public void setDifFecContAt(int difFecContAt) {
        this.difFecContAt = difFecContAt;
    }

    public int getDifFecContAt() {
        return difFecContAt;
    }

    public void setDifFecContPed(int difFecContPed) {
        this.difFecContPed = difFecContPed;
    }

    public int getDifFecContPed() {
        return difFecContPed;
    }

    public void setAlertPen(String alertPen) {
        this.alertPen = alertPen;
    }

    public String getAlertPen() {
        return alertPen;
    }

    public void setHorAlertPen(String horAlertPen) {
        this.horAlertPen = horAlertPen;
    }

    public String getHorAlertPen() {
        return horAlertPen;
    }

    public void setAprAutPed(int aprAutPed) {
        this.aprAutPed = aprAutPed;
    }

    public int getAprAutPed() {
        return aprAutPed;
    }

    public void setFaseAbono(int faseAbono) {
        this.faseAbono = faseAbono;
    }

    public int getFaseAbono() {
        return faseAbono;
    }

    public void setValiParm(int valiParm) {
        this.valiParm = valiParm;
    }

    public int getValiParm() {
        return valiParm;
    }

    private static class AuthorityComparator implements Comparator<GrantedAuthority>, Serializable {
        public int compare(GrantedAuthority g1, GrantedAuthority g2) {
            // Neither should ever be null as each entry is checked before adding it to the set.
            // If the authority is null, it is a custom authority and should precede others.
            if (g2.getAuthority() == null) {
                return -1;
            }

            if (g1.getAuthority() == null) {
                return 1;
            }

            return g1.getAuthority().compareTo(g2.getAuthority());
        }
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void setAuthorities(Collection<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public Collection<GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public void setAccountNonExpired(boolean accountNonExpired) {
        this.accountNonExpired = accountNonExpired;
    }

    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    public void setAccountNonLocked(boolean accountNonLocked) {
        this.accountNonLocked = accountNonLocked;
    }

    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    public void setCredentialsNonExpired(boolean credentialsNonExpired) {
        this.credentialsNonExpired = credentialsNonExpired;
    }

    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setNomClie(String nomClie) {
        this.nomClie = nomClie;
    }

    public String getNomClie() {
        return nomClie;
    }

    public void setCodClie(String codClie) {
        this.codClie = codClie;
    }

    public String getCodClie() {
        return codClie;
    }

    public void setCodSucuHtb(String codSucuHtb) {
        this.codSucuHtb = codSucuHtb;
    }

    public String getCodSucuHtb() {
        return codSucuHtb;
    }

    public void setDesSucuHtb(String desSucuHtb) {
        this.desSucuHtb = desSucuHtb;
    }

    public String getDesSucuHtb() {
        return desSucuHtb;
    }

    public void setUsuWeb(String usuWeb) {
        this.usuWeb = usuWeb;
    }

    public String getUsuWeb() {
        return usuWeb;
    }

    public void setPasWeb(String pasWeb) {
        this.pasWeb = pasWeb;
    }

    public String getPasWeb() {
        return pasWeb;
    }

    public void setCiaWeb(String ciaWeb) {
        this.ciaWeb = ciaWeb;
    }

    public String getCiaWeb() {
        return ciaWeb;
    }

    public void setIndActi(int indActi) {
        this.indActi = indActi;
    }

    public int getIndActi() {
        return indActi;
    }

    public void setDesPerfil(String desPerfil) {
        this.desPerfil = desPerfil;
    }

    public String getDesPerfil() {
        return desPerfil;
    }

    public void setNomUsuaWeb(String nomUsuaWeb) {
        this.nomUsuaWeb = nomUsuaWeb;
    }

    public String getNomUsuaWeb() {
        return nomUsuaWeb;
    }
}
